package com.principle.inverse.improve;

public class DependecyInversion {
    public static void main(String[] args) {
        //客户端无需改变
        Person person = new Person();
        person.receive(new Email());

        person.receive(new Weixin());
    }
}

// 定义接口
interface IReceiver {
    public String getInfo();
}

class Email implements IReceiver {

    @Override
    public String getInfo() {
        return "电子邮件消息";
    }
}

class Weixin implements IReceiver {

    @Override
    public String getInfo() {
        return "微信消息";
    }
}

// 完成Person接收消息的功能
// 方式2
class Person {
    // 这里我们是对接口的依赖
    public void receive(IReceiver iReceiver){
        System.out.println(iReceiver.getInfo());
    }
}